package com.frikinet.lifeguard.gui;

import java.awt.CardLayout;

import javax.swing.JPanel;

import com.frikinet.lifeguard.App;
import com.frikinet.lifeguard.events.MonthSelectedListener;
import com.frikinet.lifeguard.events.PostSelectedEvent;
import com.frikinet.lifeguard.events.PostSelectedListener;
import com.frikinet.lifeguard.events.UserSelectedEvent;
import com.frikinet.lifeguard.events.UserSelectedListener;
import com.frikinet.lifeguard.events.YearMonthSelectedEvent;
import com.frikinet.lifeguard.events.YearSelectedListener;

public class ViewersPanel extends JPanel
implements PostSelectedListener, UserSelectedListener, YearSelectedListener, MonthSelectedListener
{
	private static final long serialVersionUID = 1L;

	private static final String HOME = "home";
	private static final String USER = "user";
	private static final String YEAR = "year";
	private static final String MONTH = "month";
	private static final String POST = "post";
	
	private CardLayout cards;
	
	public ViewersPanel()
	{
		super();
		
		buildGUI();
		
		App.events.addPostSelectedListener(this);
		App.events.addUserSelectedListener(this);
		App.events.addYearSelectedListener(this);
		App.events.addMonthSelectedListener(this);
	}
	
	private void buildGUI()
	{
		cards = new CardLayout();
		setLayout(cards);
		
		add(new HomeHtmlPanel(), HOME);
		
		add(new PostViewer(), POST);
		
		add(new UserViewer(), USER);
		
		add(new YearViewer(), YEAR);
		
		add(new MonthViewer(), MONTH);
		
		cards.show(this, HOME);
	}

	@Override
	public void userSelected(UserSelectedEvent event)
	{
		cards.show(this, USER);
	}

	@Override
	public void postSelected(PostSelectedEvent event)
	{
		cards.show(this, POST);
	}

	@Override
	public void monthSelected(YearMonthSelectedEvent event)
	{
		cards.show(this, MONTH);
	}

	@Override
	public void yearSelected(YearMonthSelectedEvent event)
	{
		cards.show(this, YEAR);
	}
}
